package czy.demo.controller;

import czy.demo.pojo.Person;
import czy.demo.service.NamedParameterJdbcTemplateService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * NamedParameterJdbcTemplate测试Controller
 * 按字面意思来说，应该是以命名参数向sql语句传递参数，
 * 而JdbcTemplate是以？标识sql语句中参数，使用数组按顺序传递参数
 */
@RestController
@RequestMapping("/named")
public class NamedJdbcTemplateController {

    @Autowired
    private NamedParameterJdbcTemplate jdbcTemplate;

    @Autowired
    private NamedParameterJdbcTemplateService jdbcTemplateService;

    @GetMapping("/query/{id}")
    public Person getPersonById(@PathVariable Integer id){
        Person result = null;
        result = this.jdbcTemplateService.getOneByIdWithResultSetExtractor(id);
        return result;
    }

}
